<template>
  <div class="app-container">
    <el-table
      v-loading="loading"
      :data="tableData"
    >
      <el-table-column label="标题"  prop="title" />
      <el-table-column prop="fileType" label="文件类型" width="120">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.mc_file_type"
            :value="scope.row.fileType"
          />
        </template>
      </el-table-column>
      <el-table-column label="产品类型"  prop="productType" width="200">
        <template slot-scope="scope">
          {{ dict.type.mc_product_type.find(v => v.value == scope.row.productType).label }}
        </template>
      </el-table-column>
      <el-table-column label="是否公开" prop="isOpen" width="120">
        <template slot-scope="scope">
          {{scope.row.isOpen === 0 ? '不公开':'公开' }}
        </template>
      </el-table-column>
      <el-table-column label="发布者"  prop="nickName" width="120"/>
      <el-table-column label="发布时间" prop="createTime" width="200">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.createTime, "{y}-{m}-{d}  {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="versionDesc" width="120">
      <template slot-scope="scope">
        <dict-tag
          :options="dict.type.review_status"
          :value="scope.row.reviewState"
        />
      </template>
    </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="180"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleDown(scope.row)"
          >下载</el-button
          >
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleDown(scope.row)"
          >下载</el-button
          >-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleReview(scope.row)"
          >审核</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['device:video:del']"
          >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改设备版本对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="审核结果" prop="reviewState">
          <el-select v-model="form.reviewState" @change="selectChange" placeholder="选择结果">
            <el-option
              v-for="item in form.options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发送邮件通知" prop="isEmail">
          <el-select v-model="form.isEmail" placeholder="请选择">
            <el-option
              v-for="dict in dict.type.mc_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核备注" prop="reviewRemark">
          <el-input
            type="textarea"
            :rows="2"
            v-model="form.reviewRemark"
            controls-position="right"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>

import { getReviewInfo, commitReviewResult, delProductReviewInfo } from '@/api/product/productInfoData'
import { MessageBox } from 'element-ui'

export default {
  name: "ReviewMgr",
  props: {
    productTypeId: {
      type: String,
    },
  },
  dicts: ["review_status", "mc_file_type", "mc_product_type", 'mc_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      tableData: [],
      // 弹出层标题
      title: "审核操作",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rangeTime: null,
        beginTime: null,
        endTime: null,
      },
      // 表单参数
      form: {
      },
      //表格数据
      list: [],
      // 表单校验
      rules: {
        reviewState: [
          { required: true, message: "审核结果必须选择", trigger: "blur" },
        ],
        reviewRemark: [
          { required: true, message: "审核备注不能为空", trigger: "blur" },
        ],
      },
      productType: null,
      baseURL: process.env.VUE_APP_DOWNLOAD_API,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备版本列表 */
    getList() {
      this.loading = true;
      getReviewInfo(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        productId: this.productId,
        options: [{
          value: 1,
          label: '通过'
        }, {
          value: 2,
          label: '不通过'
        }],
        reviewRemark: null,
        reviewState: null,
        reviewId: null,
        isEmail: '1'
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    handleDown(row){
      window.open(this.baseURL+ '/app/'+ row.url) ;
    },

    selectChange(value) {
      if(value === 1) {
        this.form.reviewRemark = '通过';
      }
    },

    /** 审核 */
    handleReview(row) {
      // 通过的就不能再更改了
      if(1 != row.reviewState){
        this.reset();
        this.form.reviewId = row.reviewId;
        this.productType = row.productType;
        this.open = true;
      }
      else{
        this.$modal.msgWarning("审核通过就不能再操作了");
      }
    },
    //删除视频教程
    handleDelete(row){
      MessageBox.confirm('此操作将永久删除该文件，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delProductReviewInfo({id:row.reviewId}).then((res)=>{
          if(res.code == 200 ){
            this.$modal.msgSuccess("删除成功");
            this.getList()
          }
        })
      }).catch(() => {
        // 用户点击“取消”
        console.log("已取消");
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let modifyParam={
            reviewId    : this.form.reviewId,
            reviewState : this.form.reviewState,
            reviewRemark:  this.form.reviewRemark,
            productType : this.productType,
            isEmail: this.form.isEmail
          };
          commitReviewResult(modifyParam).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
  },
};
</script>
<style scoped></style>
